package com.info.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.info.model.UserModel;
import com.info.mapper.UserMapper;

@Service
public class UserService {
	@Autowired
    UserMapper userMapper;
	
    public UserModel getUser(String username, String password) {
        System.out.println("enter service");
        return userMapper.getUser(username, password);
    }
    
    public void insertUser(String username, String password, String phone, String email, String editTime)
    {
        System.out.println("insert user");
        UserModel user = new UserModel();
        user.setUsername(username);
        user.setPassword(password);
        user.setPhone(phone);
        user.setEmail(email);
        user.setEditTime(editTime);
        userMapper.insertUser(user);
    }
    
    public void insertUserTest(String username, String password) {
    	System.out.println("insert user");
        UserModel user = new UserModel();
        user.setUsername(username);
        user.setPassword(password);
        userMapper.insertUserTest(user);
    }
    
    public int deleteUser(String username, String password)
    {
        System.out.println("delete user");
    	if(getUser(username, password) == null) {
    		return 0;
    	} else {
    		UserModel user = new UserModel();
            user.setUsername(username);
            userMapper.deleteUser(user);
            return 1;
    	}
    }
    
    public List<UserModel> getAllUsers() {
		return userMapper.getAllUsers();
	}
}
